#include "settingdialog.h"
#include <DLabel>
#include <QFormLayout>

SettingDialog::SettingDialog(bool en, bool sel, bool cp, DDialog *parent)
    : DDialog(parent) {
  setWindowTitle(tr("Setting"));
  auto w = new QWidget(this);
  auto flayout = new QFormLayout(w);
  addContent(w, Qt::AlignCenter);
  swen = new DSwitchButton(this);
  swen->setChecked(en);
  connect(swen, &DSwitchButton::checkedChanged, this,
          [=](bool b) { this->setYoudaoEnabled(b); });
  flayout->addRow(tr("Enable"), swen);

  swsel = new DSwitchButton(this);
  swsel->setChecked(sel);
  swsel->setEnabled(en);
  connect(swsel, &DSwitchButton::checkedChanged, this,
          [=](bool v) { emit this->sigSelEnabled(v); });
  flayout->addRow(tr("EnableSel"), swsel);
  swcp = new DSwitchButton(this);
  swcp->setChecked(cp);
  swcp->setEnabled(en);
  connect(swcp, &DSwitchButton::checkedChanged, this,
          [=](bool v) { emit this->sigCpEnabled(v); });
  flayout->addRow(tr("EnableCp"), swcp);

  addSpacing(10);
  addContent(new DLabel(tr("SetEffect"), this), Qt::AlignCenter);
}

void SettingDialog::setYoudaoEnabled(bool v) {
  swsel->setEnabled(v);
  swcp->setEnabled(v);
  emit sigEnabled(v);
}

void SettingDialog::setSelEnabled(bool v) { swsel->setChecked(v); }

void SettingDialog::setCpEnabled(bool v) { swcp->setChecked(v); }
